package com.example.easyexcel.exports.customized.selected;


import com.example.easyexcel.exports.customized.util.ExportUtil;
import lombok.Data;

/**
 * 解析、存储单元格的下拉框
 * */
@Data
public class ExcelSelectedResolve {
    /**
     * 下拉内容
     */
    private String[] source;

    /**
     * 设置下拉框的起始行，默认为第二行
     */
    private int firstRow;

    /**
     * 设置下拉框的结束行，默认为最后一行
     */
    private int lastRow;

    public String[] resolveSelectedSource(ExcelSelected excelSelected) {
        String[] source = excelSelected.source();
        if ( source.length > 0) {
            return source;// 获取固定下拉框的内容
        }else{
            Class<? extends ExcelDynamicSelect>[] classes = excelSelected.sourceClass();// 获取动态下拉框的内容
            if (classes.length > 0) {
                // 动态下拉框都从环境中获取
                ExcelDynamicSelect excelDynamicSelect = ExportUtil.getContext().getBean(classes[0]) ;
                if (null!=excelDynamicSelect) {
                    return excelDynamicSelect.getSource();
                }
            }
        }
        return null;
    }

}